package com.stoney.http;

import org.apache.http.client.HttpClient;
import org.apache.http.client.utils.HttpClientUtils;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.impl.conn.PoolingClientConnectionManager;

/**
 * Created by Stony on 2015/12/12.
 */
public class HttpRequestManager {

    static PoolingClientConnectionManager connectionManager;

    public static RequestQueue newRequestQueue() {
        return newRequestQueue(null);
    }

    private static RequestQueue newRequestQueue(HttpStack httpStack) {
        if(httpStack == null){
            httpStack = new HttpClientStack(createHttpClient());
        }
        BasicNetwork network = new BasicNetwork(httpStack);
        RequestQueue queue = new RequestQueue(network);
        queue.start();
        return queue;
    }
    public static HttpClient createHttpClient(){
//        if(connectionManager == null){
//            connectionManager = new PoolingClientConnectionManager();
//            connectionManager.setDefaultMaxPerRoute(3);
//            connectionManager.setMaxTotal(6);
//        }

        return new DefaultHttpClient();
    }
}
